
package View;

import Client.Client;
import Module.Team;
import Module.User;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author CCD gruppe 2
 */
public class SessionPanelForTabbedPane extends javax.swing.JPanel {

    private TeamSessionInfoPanel expertGroupPanel;
    private javax.swing.JLabel dateLabel;
    private javax.swing.JPanel evaluatingPanel;
    private javax.swing.JPanel informationPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane expertGroupsTabbedPane;
    private javax.swing.JTextArea evaluationTextArea;
    private javax.swing.JPanel preparationPanel;
    private javax.swing.JTextField sessionDateTextField;
    private javax.swing.JTabbedPane sessionInfoTabbedPane;
    private javax.swing.JLabel sessionNameLabel;
    private javax.swing.JTextField sessionNameTextField;
    private javax.swing.JComboBox sessionPlaceDropDown;
    private javax.swing.JLabel sessionPlaceLabel;
    private javax.swing.JTextArea sessionPreparationTextArea;
    private javax.swing.JTextField sessionTimeFromTextField;
    private javax.swing.JLabel sessionTimeLabel;
    private javax.swing.JTextField sessionToTimeTextField;
    private javax.swing.JList teamMemberList;
    private DefaultComboBoxModel sessionPlaceModel;
    private int selectedteam = 0;
    ArrayList<User> users = new ArrayList<User>();
    private int sessionId;


    ArrayList<TeamSessionInfoPanel> teamSessionInfoPanels = new ArrayList<TeamSessionInfoPanel>();

    /** Creates new form SessionPanelForTabbedPane */
    public SessionPanelForTabbedPane() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        expertGroupPanel = new TeamSessionInfoPanel();
        sessionPlaceModel = new DefaultComboBoxModel();

        sessionInfoTabbedPane = new javax.swing.JTabbedPane();
        informationPanel = new javax.swing.JPanel();
        sessionNameTextField = new javax.swing.JTextField();
        sessionNameLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        sessionPlaceDropDown = new javax.swing.JComboBox();
        dateLabel = new javax.swing.JLabel();
        sessionTimeLabel = new javax.swing.JLabel();
        sessionTimeFromTextField = new javax.swing.JTextField();
        sessionPlaceLabel = new javax.swing.JLabel();
        sessionToTimeTextField = new javax.swing.JTextField();
        sessionDateTextField = new javax.swing.JTextField();
        preparationPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        sessionPreparationTextArea = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        evaluatingPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        evaluationTextArea = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        expertGroupsTabbedPane = new javax.swing.JTabbedPane();
        teamMemberList = new javax.swing.JList();

        expertGroupsTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        sessionInfoTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

        sessionPlaceDropDown.setModel(sessionPlaceModel);
        expertGroupPanel = new TeamSessionInfoPanel();

        sessionNameLabel.setText("Navn:");

        jLabel3.setText("-");

        dateLabel.setText("Dato:");

        sessionTimeLabel.setText("Klokkeslett:");

        sessionTimeFromTextField.setText("Fra");

        sessionPlaceLabel.setText("Plass:");

        sessionToTimeTextField.setText("Til");

        org.jdesktop.layout.GroupLayout informationPanelLayout = new org.jdesktop.layout.GroupLayout(informationPanel);
        informationPanel.setLayout(informationPanelLayout);
        informationPanelLayout.setHorizontalGroup(
            informationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, informationPanelLayout.createSequentialGroup()
                .add(202, 202, 202)
                .add(informationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(informationPanelLayout.createSequentialGroup()
                        .add(sessionTimeLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 157, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, sessionPlaceDropDown, 0, 232, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, informationPanelLayout.createSequentialGroup()
                        .add(informationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, sessionNameLabel)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, dateLabel)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, sessionPlaceLabel)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, sessionNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(informationPanelLayout.createSequentialGroup()
                        .add(sessionTimeFromTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(sessionToTimeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                        .add(1, 1, 1))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, informationPanelLayout.createSequentialGroup()
                        .add(sessionDateTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE)
                        .add(1, 1, 1)))
                .add(199, 199, 199))
        );
        informationPanelLayout.setVerticalGroup(
            informationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(informationPanelLayout.createSequentialGroup()
                .add(75, 75, 75)
                .add(sessionNameLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sessionNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(5, 5, 5)
                .add(dateLabel)
                .add(2, 2, 2)
                .add(sessionDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sessionTimeLabel)
                .add(8, 8, 8)
                .add(informationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(sessionToTimeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(sessionTimeFromTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sessionPlaceLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sessionPlaceDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(108, Short.MAX_VALUE))
        );

        sessionInfoTabbedPane.addTab("Informasjon", informationPanel);

        sessionPreparationTextArea.setColumns(20);
        sessionPreparationTextArea.setLineWrap(true);
        sessionPreparationTextArea.setRows(5);
        jScrollPane2.setViewportView(sessionPreparationTextArea);

        jLabel7.setText("Forberedelse til sesjon:");

        org.jdesktop.layout.GroupLayout preparationPanelLayout = new org.jdesktop.layout.GroupLayout(preparationPanel);
        preparationPanel.setLayout(preparationPanelLayout);
        preparationPanelLayout.setHorizontalGroup(
            preparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(preparationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(preparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                    .add(jLabel7))
                .addContainerGap())
        );
        preparationPanelLayout.setVerticalGroup(
            preparationPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(preparationPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel7)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                .addContainerGap())
        );

        sessionInfoTabbedPane.addTab("Forberedelse", preparationPanel);

        evaluationTextArea.setColumns(20);
        evaluationTextArea.setLineWrap(true);
        evaluationTextArea.setRows(5);
        jScrollPane1.setViewportView(evaluationTextArea);

        jLabel1.setText("Evaluering av sesjon:");

        org.jdesktop.layout.GroupLayout evaluatingPanelLayout = new org.jdesktop.layout.GroupLayout(evaluatingPanel);
        evaluatingPanel.setLayout(evaluatingPanelLayout);
        evaluatingPanelLayout.setHorizontalGroup(
            evaluatingPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(evaluatingPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(evaluatingPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                    .add(jLabel1))
                .addContainerGap())
        );
        evaluatingPanelLayout.setVerticalGroup(
            evaluatingPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(evaluatingPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                .addContainerGap())
        );

        sessionInfoTabbedPane.addTab("Evaluering", evaluatingPanel);

        sessionInfoTabbedPane.addTab("Ekspertgrupper", expertGroupsTabbedPane);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 680, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(sessionInfoTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 471, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(sessionInfoTabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                .addContainerGap())
        );

    }// </editor-fold>
    /**
     * Adds a team tab to the team panel.
     * @param teamSessionInfoPanel
     * @param teamName
     */
    public void addTeamTab(TeamSessionInfoPanel teamSessionInfoPanel, String teamName){
        int teamNr = expertGroupsTabbedPane.getTabCount();
        expertGroupsTabbedPane.addTab(teamName, teamSessionInfoPanel);
        teamSessionInfoPanels.add(teamSessionInfoPanel);
    }

    /**
     * Inserts session data into the gui elements.
     * @param name
     * @param date
     * @param time
     * @param places
     * @param facilitators
     * @param secretaries
     * @param availableExperts
     * @param addedExperts
     */
    public void insertData(String name, String date, String time, ArrayList<String> places, ArrayList<String> facilitators,
            ArrayList<String> secretaries, ArrayList<String> availableExperts, ArrayList<String> addedExperts){

        sessionPlaceModel.removeAllElements();
        sessionNameTextField.setText(name);
        sessionDateTextField.setText(date);
        sessionTimeFromTextField.setText(time);
        sessionToTimeTextField.setText(time);

        for(int i=0; i<places.size(); i++){
            sessionPlaceModel.addElement(places.get(i));
        }
    }


    /**
     * Sets the gui elements to non-focusable.
     */
    public void isInfoPanel(){
        sessionNameTextField.setFocusable(false);
        sessionDateTextField.setFocusable(false);
        sessionToTimeTextField.setFocusable(false);
        sessionTimeFromTextField.setFocusable(false);
        evaluationTextArea.setFocusable(false);
        expertGroupsTabbedPane.setFocusable(false);
        sessionPlaceDropDown.setEnabled(false);
        sessionPreparationTextArea.setFocusable(false);


    }

    /**
     * Sets the gui elements to focusable.
     */
    public void editButtonClicked(){
        sessionNameTextField.setFocusable(true);
        sessionDateTextField.setFocusable(true);
        sessionToTimeTextField.setFocusable(true);
        sessionTimeFromTextField.setFocusable(true);
        evaluationTextArea.setFocusable(true);
        sessionPreparationTextArea.setFocusable(true);
        sessionPlaceDropDown.setEnabled(true);
        sessionPreparationTextArea.setFocusable(true);
        for(int i=0; i<teamSessionInfoPanels.size();i++){
            teamSessionInfoPanels.get(i).editButtonPressed();
        }
    }

    /**
     * Sets the session and team gui elements to non-focusable.
     */
    public void saveButtonClicked(){
        sessionNameTextField.setFocusable(false);
        sessionDateTextField.setFocusable(false);
        sessionToTimeTextField.setFocusable(false);
        sessionTimeFromTextField.setFocusable(false);
        evaluationTextArea.setFocusable(false);
        sessionPreparationTextArea.setFocusable(false);
        sessionPlaceDropDown.setEnabled(false);
        sessionPreparationTextArea.setFocusable(false);
        for(int i=0; i<teamSessionInfoPanels.size();i++){
            teamSessionInfoPanels.get(i).isInfoPanel();
        }
    }

    /*
     * Getters and setters
     */
    public JLabel getDateLabel() {
        return dateLabel;
    }

    public JPanel getEvaluatingPanel() {
        return evaluatingPanel;
    }

    public JPanel getExpertGroupPanel() {
        return expertGroupPanel;
    }

    public JPanel getInformationPanel() {
        return informationPanel;
    }

    public JLabel getjLabel1() {
        return jLabel1;
    }

    public JLabel getjLabel3() {
        return jLabel3;
    }

    public JLabel getjLabel7() {
        return jLabel7;
    }

    public JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    public JScrollPane getjScrollPane2() {
        return jScrollPane2;
    }

    public JTextArea getSessionEvaluationTextArea() {
        return evaluationTextArea;
    }

    public JPanel getPreparationPanel() {
        return preparationPanel;
    }

    public JTextField getSessionDateTextField() {
        return sessionDateTextField;
    }
    public JTabbedPane getSessionInfoTabbedPane() {
        return sessionInfoTabbedPane;
    }

    public JLabel getSessionNameLabel() {
        return sessionNameLabel;
    }

    public JTextField getSessionNameTextField() {
        return sessionNameTextField;
    }

    public JComboBox getSessionPlaceDropDown() {
        return sessionPlaceDropDown;
    }

    public JLabel getSessionPlaceLabel() {
        return sessionPlaceLabel;
    }

    public JTextArea getSessionPreparationTextArea() {
        return sessionPreparationTextArea;
    }

    public JTextField getSessionTimeFromTextField() {
        return sessionTimeFromTextField;
    }

    public JLabel getSessionTimeLabel() {
        return sessionTimeLabel;
    }

    public JTextField getSessionToTimeTextField() {
        return sessionToTimeTextField;
    }

    public JList getTeamMemberList() {
        return teamMemberList;
    }


    public String getSessionName(){
        return sessionNameTextField.getText();
    }

    public String getSessionDate(){
        return sessionDateTextField.getText();
    }

    public String getSessionTimeFrome(){
        return sessionTimeFromTextField.getText();
    }
    public String getSessionTimeTo(){
        return sessionToTimeTextField.getText();
    }
    public int getSelectedTeam() {
        return selectedteam;
    }

    public TeamSessionInfoPanel getSelectedTeamPanel(){
        int selectedTeamTab = expertGroupsTabbedPane.getSelectedIndex();
        return teamSessionInfoPanels.get(selectedTeamTab);
    }

    public String getSessionEvaluation(){
        return evaluationTextArea.getText();
    }

    public void setSelectedteam(int selectedteam) {
        this.selectedteam = selectedteam;
    }

    public void setSessionName(String name){
        sessionNameTextField.setText(name);
    }
    public int getTeamSessionInfoPanelsSize(){
        return teamSessionInfoPanels.size();
    }

    public void setSessionDate(String date){
        sessionDateTextField.setText(date);
    }

    public void setSessionFromeTime(String time){
        sessionTimeFromTextField.setText(time);
    }

    public void setSessionToTime(String time){
        sessionToTimeTextField.setText(time);
    }

    public void setSessionPlaces(ArrayList<String> places){
        for(int i=0; i<places.size(); i++){
            sessionPlaceModel.addElement(places.get(i));
        }
    }

    public void setSessionPlace(String place){
        sessionPlaceModel.addElement(place);
    }


    public JTabbedPane getExpertGroupsTabbedPane() {
        return expertGroupsTabbedPane;
    }

    public DefaultComboBoxModel getSessionPlaceModel() {
        return sessionPlaceModel;
    }

    public TeamSessionInfoPanel getTeamInfoPanel(int index){
        if(!teamSessionInfoPanels.isEmpty()){
            return teamSessionInfoPanels.get(index);
        }
        return null;
    }

    public ArrayList<TeamSessionInfoPanel> getTeamSessionInfoPanels() {
        return teamSessionInfoPanels;
    }
    public TeamSessionInfoPanel getLastteamSessionOnfoPanel(){
        return teamSessionInfoPanels.get(teamSessionInfoPanels.size()-1);
    }

    public int getSessionId() {
        return sessionId;
    }

    public void setSessionId(int sessionId) {
        this.sessionId = sessionId;
    }


}
